﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.Web.Services;

using System.Text;

public partial class Order_OrderEdit : System.Web.UI.Page, ICallbackEventHandler
{
    string result = "";

    public int zsl;
    public decimal zbzje;
    public decimal zsjje;

    private Model.ORDERDOC Order
    {
        get
        {
            Model.ORDERDOC order = null;
            if (ViewState["Order"] != null)
            {
                order = (Model.ORDERDOC)ViewState["Order"]; 
            }
            return order;
        }
        set
        {
            ViewState["Order"] = value;
        }
    }

    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("400101");       
        if (!IsPostBack)
        {
            if (HttpContext.Current.Session["ReturnProductCodes"] != null)
            {
                ViewState["sp_l_splist"] = (List<string>)HttpContext.Current.Session["ReturnProductCodes"];
                HttpContext.Current.Session["ReturnProductCodes"] = null;
            }
            if (Request.QueryString["code"] == null)
            {
                return;
            }
            if (Request.QueryString["t"] != null)
            {
                Lock();
            }
            if (Request.QueryString["ts"] != null)
            {
                ((Button)BUTTONDJ1.Controls[22]).Visible = true;
            }
            GetData();
            GetZFData();
            GetOrderInfo();
            BindOrderNote();
            ((Button)BUTTONDJ1.Controls[24]).Visible = true;
            ((Button)BUTTONDJ1.Controls[26]).Visible = true;
        }

        if (ViewState["sp_l_splist"] != null)
        {
            selectsp();
            btnEvent();
        }
        if (lblnewzfbj.Text.Trim() != "")
        {
            selectzf();
            ((Button)Page.FindControl("zf_btn_0")).Click += new EventHandler(this.Button2_Click);

            ((DropDownList)tab_zf.Rows[0].Cells[2].Controls[0]).SelectedIndexChanged += new EventHandler(DDLCHANGE_Click);
        }


    }
    private void BindOrderNote()
    {
        DataSet dst = new BLL.ORDERNOTE().GetOrderNoteById(Request.QueryString["code"].ToString().Trim());
        ORDERNOTEListControl1.Bind(dst);
    }
    private void btnEvent()
    {
        if (ViewState["sp_l_splist"] != null)
        {
            List<string> pcodes = (List<string>)ViewState["sp_l_splist"];
            for (int a = 0; a < pcodes.Count; a++)
            {
                Button bb = new Button();
                bb = (Button)Page.FindControl("sp_btn_" + a.ToString());
                bb.Click += new EventHandler(Button1_Click);
            }
        }
    }
    private void selectsp()
    {

        if (ViewState["sp_l_splist"] != null)
        {

            List<string> pcodes = (List<string>)ViewState["sp_l_splist"];


            for (int a = 0; a < pcodes.Count; a++)
            {
                string astr = pcodes[a].ToString();
                string s = astr.Split(',')[0].Trim();
                HtmlTableRow row = new HtmlTableRow();
                row.ID = astr;
                HtmlTableCell cell = new HtmlTableCell();
                HtmlTableCell cell1 = new HtmlTableCell();
                HtmlTableCell cell2 = new HtmlTableCell();
                HtmlTableCell cell3 = new HtmlTableCell();
                HtmlTableCell cell4 = new HtmlTableCell();
                HtmlTableCell cell5 = new HtmlTableCell();
                HtmlTableCell cell6 = new HtmlTableCell();
                HtmlTableCell cell7 = new HtmlTableCell();
                HtmlTableCell cell8 = new HtmlTableCell();
                HtmlTableCell cell9 = new HtmlTableCell();
                HtmlTableCell cell10 = new HtmlTableCell();
                Button btn = new Button();
                btn.ID = "sp_btn_" + a.ToString();
                btn.Text = "删除";
                btn.CssClass = "input_button";
                //btn.Click += ssss;
                btn.CommandArgument = astr;


                Label lblspdm = new Label();
                lblspdm.Text = astr.Split(',')[1];
                lblspdm.ToolTip = astr.Split(',')[0];

                // pcodes.Add(lblspdm.ToolTip);

                DropDownList dllgg1 = new DropDownList();

                dllgg1.DataSource = new BLL.SHANGPIN().GetSPGG1(s).Tables[0].DefaultView;
                dllgg1.DataTextField = "ggmc";
                dllgg1.DataValueField = "ggdm";
                dllgg1.DataBind();

                DropDownList dllgg2 = new DropDownList();

                dllgg2.DataSource = new BLL.SHANGPIN().GetSPGG2(s).Tables[0].DefaultView;
                dllgg2.DataTextField = "ggmc";
                dllgg2.DataValueField = "ggdm";
                dllgg2.DataBind();

                TextBox txtsl = new TextBox();
                txtsl.Text = "1";
                txtsl.Width = 50;
                txtsl.CssClass = "zt8";

                TextBox txtzk = new TextBox();
                txtzk.Text = lblzk.Text;
                txtzk.Width = 50;

                cell.Controls.Add(btn);
                cell1.Controls.Add(lblspdm);

                cell2.Controls.Add(dllgg1);
                cell3.Controls.Add(dllgg2);
                cell4.Controls.Add(txtsl);

                Model.COMMODITY_AUTO ca = new Model.COMMODITY_AUTO();
                ca = new BLL.COMMODITY_AUTO().GetModel(s);
                string bzsj = new BLL.SHANGPIN().GetModel(s).BZSJ.ToString().Trim();
                if (bzsj == "" || bzsj is DBNull) { bzsj = "0"; }
                Decimal bzj = Decimal.Parse(bzsj);
                cell5.InnerText = Decimal.Round(bzj, 2).ToString();
                cell6.Controls.Add(txtzk);
                Decimal sjdj = Decimal.Parse(txtzk.Text.Trim()) * decimal.Parse(cell5.InnerText.Trim());
                cell7.InnerText = Decimal.Round(sjdj, 2).ToString();
                Decimal bzjg = Int32.Parse(txtsl.Text.Trim()) * bzj;
                cell8.InnerText = Decimal.Round(bzjg, 2).ToString();
                Decimal sjjg = bzjg * Decimal.Parse(txtzk.Text.Trim());
                cell9.InnerText = Decimal.Round(sjjg, 2).ToString();
                cell10.InnerText = Decimal.Round(ca == null ? 0.00M : ca.CA_WEIGHT, 2).ToString();

                cell.Width = "6%";
                cell1.Width = "30%";
                cell2.Width = "6%";
                cell3.Width = "6%";
                cell4.Width = "6%";
                cell5.Width = "8%";
                cell6.Width = "6%";
                cell7.Width = "8%";
                cell8.Width = "8%";
                cell9.Width = "8%";
                cell10.Width = "8%";

                cell.Attributes.Add("class", "td_left1");
                cell1.Attributes.Add("class", "td_left1");
                cell2.Attributes.Add("class", "td_left1");
                cell3.Attributes.Add("class", "td_left1");
                cell4.Attributes.Add("class", "td_left1");
                cell5.Attributes.Add("class", "td_left2");
                cell6.Attributes.Add("class", "td_left1");
                cell7.Attributes.Add("class", "td_left2");
                cell8.Attributes.Add("class", "td_left2");
                cell9.Attributes.Add("class", "td_left2");
                cell10.Attributes.Add("class", "td_right2");



                row.Cells.Add(cell);
                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                row.Cells.Add(cell4);
                row.Cells.Add(cell5);
                row.Cells.Add(cell6);
                row.Cells.Add(cell7);
                row.Cells.Add(cell8);
                row.Cells.Add(cell9);
                row.Cells.Add(cell10);
                row.Style.Value = "z1";
                row.Align = "left";
                row.BgColor = "#f5f5f5";

                tab_sp.Rows.Add(row);
            }

        }

    }
    private void selectzf()
    {
        HtmlTableRow row = new HtmlTableRow();

        HtmlTableCell cell = new HtmlTableCell();
        HtmlTableCell cell1 = new HtmlTableCell();
        HtmlTableCell cell2 = new HtmlTableCell();
        HtmlTableCell cell3 = new HtmlTableCell();
        HtmlTableCell cell4 = new HtmlTableCell();
        HtmlTableCell cell5 = new HtmlTableCell();
        HtmlTableCell cell6 = new HtmlTableCell();
        HtmlTableCell cell7 = new HtmlTableCell();
        HtmlTableCell cell8 = new HtmlTableCell();
        HtmlTableCell cell9 = new HtmlTableCell();
        HtmlTableCell cell10 = new HtmlTableCell();


        Button btn = new Button();
        btn.ID = "zf_btn_0";
        btn.Text = "删除";
        btn.CssClass = "input_button";



        TextBox txtzhanghao = new TextBox();
        txtzhanghao.Width = 124;

        DropDownList ddl_zfmx_jylx = new DropDownList();
        ListItem tempItem1 = new ListItem("即时到帐", "001");
        ListItem tempItem2 = new ListItem("担保交易", "002");
        ListItem tempItem3 = new ListItem("结余款", "003");
        ddl_zfmx_jylx.Items.Add(tempItem1);
        ddl_zfmx_jylx.Items.Add(tempItem2);
        ddl_zfmx_jylx.Items.Add(tempItem3);
        ddl_zfmx_jylx.AutoPostBack = true;
        ddl_zfmx_jylx.Width = 55;



        DropDownList dllgg1 = new DropDownList();

        DataSet dst = new BLL.PAYTYPE_DEALTYPE().P_DealType_GetPayTypeByCode(ddl_zfmx_jylx.SelectedValue);
        ListItem tempItem;

        for (int i = 0; i < dst.Tables[0].Rows.Count; i++)
        {
            tempItem = new ListItem();
            tempItem.Text = dst.Tables[0].Rows[i]["PT_NAME"].ToString();
            tempItem.Value = dst.Tables[0].Rows[i]["PT_CODE"].ToString() + "|" + dst.Tables[0].Rows[i]["PT_HAVEDEAL"].ToString();
            dllgg1.Items.Add(tempItem);
        }
        dllgg1.ID = "ddlzffs";
        dllgg1.Width = 140;

        TextBox txtzfje = new TextBox();
        txtzfje.Width = 52;
        txtzfje.CssClass = "zt8";

        //TextBox txtzfrq = new TextBox();
        //txtzfrq.Width = 110;
        //txtzfrq.Attributes.Add("onfocus", "setday(this);");


        TextBox txtjyh = new TextBox();
        txtjyh.Width = 124;

        TextBox txtjyrq = new TextBox();
        txtjyrq.Width = 120;
        txtjyrq.Attributes.Add("onfocus", "setday(this);");
        //txtjyrq.Attributes.Add("onblur", "CalendarCancel(oCalendarChs);");

        TextBox txtbz = new TextBox();
        txtbz.Width = 200;

        Label lblsdf = new Label();
        lblsdf.Text = "0.00";


        cell8.InnerHtml = "&nbsp;";
        cell9.InnerHtml = "&nbsp;";
        cell10.InnerHtml = "&nbsp;";


        cell.Width = "60px";
        cell1.Width = "130px";
        cell2.Width = "60px";
        cell3.Width = "150px";
        cell4.Width = "60px";
        cell5.Width = "130px";
        cell6.Width = "130px";
        cell7.Width = "";
        cell9.Width = "130px";
        cell8.Width = "60px";
        cell10.Width = "80px";

        cell.Attributes.Add("class", "td_left1");
        cell1.Attributes.Add("class", "td_left1");
        cell2.Attributes.Add("class", "td_left1");
        cell3.Attributes.Add("class", "td_left1");
        cell4.Attributes.Add("class", "td_left1");
        cell5.Attributes.Add("class", "td_left1");
        cell6.Attributes.Add("class", "td_left1");
        cell7.Attributes.Add("class", "td_left1");
        cell8.Attributes.Add("class", "td_left1");
        cell9.Attributes.Add("class", "td_left1");
        cell10.Attributes.Add("class", "td_right1");

        cell.Controls.Add(btn);
        cell1.Controls.Add(txtzhanghao);
        cell2.Controls.Add(ddl_zfmx_jylx);
        cell3.Controls.Add(dllgg1);
        cell4.Controls.Add(txtzfje);
        cell5.Controls.Add(txtjyh);
        cell6.Controls.Add(txtjyrq);
        ////cell8.Controls.Add(lblsdf);
        ////cell9.Controls.Add(lblsdf);
        ////cell10.Controls.Add(lblsdf);
        cell7.Controls.Add(txtbz);


        row.Cells.Add(cell);
        row.Cells.Add(cell1);
        row.Cells.Add(cell2);
        row.Cells.Add(cell3);
        row.Cells.Add(cell4);
        row.Cells.Add(cell5);
        row.Cells.Add(cell6);
        row.Cells.Add(cell7);
        row.Cells.Add(cell8);
        row.Cells.Add(cell9);
        row.Cells.Add(cell10);


        row.Style.Value = "z1";
        row.Align = "left";
        row.BgColor = "#f5f5f5";



        tab_zf.Rows.Add(row);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button clickedButton = (Button)sender;
        string a = clickedButton.CommandArgument;
        List<string> pp = (List<string>)ViewState["sp_l_splist"];
        pp.Remove(a);
        ViewState["sp_l_splist"] = pp;
        tab_sp.Rows.Remove((HtmlTableRow)tab_sp.FindControl(a));
    }
    protected void DDLCHANGE_Click(object sender, EventArgs e)
    {
        DataSet dst = new BLL.PAYTYPE_DEALTYPE().P_DealType_GetPayTypeByCode(((DropDownList)sender).SelectedValue);
        ListItem tempItem;
        DropDownList ss = (DropDownList)tab_zf.Rows[0].Cells[3].Controls[0];
        ss.Items.Clear();
        for (int i = 0; i < dst.Tables[0].Rows.Count; i++)
        {
            tempItem = new ListItem();
            tempItem.Text = dst.Tables[0].Rows[i]["PT_NAME"].ToString();
            tempItem.Value = dst.Tables[0].Rows[i]["PT_CODE"].ToString() + "|" + dst.Tables[0].Rows[i]["PT_HAVEDEAL"].ToString();
            ss.Items.Add(tempItem);
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        tab_zf.Rows.Clear();
        lblnewzfbj.Text = "";
    }
    protected void btnNewZF_Click(object sender, EventArgs e)
    {
        if (tab_zf.Rows.Count > 0)
        {
            Share.Alert(Page, "每次添加1条！");
        }
        else
        {
            lblnewzfbj.Text = "sd";
            selectzf();
        }
    }
    #region 订单主信息



    private void GetOrderInfo()
    {
        string orderid = Request.QueryString["code"].ToString().Trim();
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(orderid);
        if (od == null)
        {
            Share.Alert(this.Page,""); return;
        }
        this.Order = od;
        //if (od.ORDER_LOCKER != Share.UserValue(0) && od.ORDER_LOCKER != "000" && od.ORDER_LOCKER != "")
        //{ Response.Redirect(BLL.Common.GetWebPath() + "/Error.aspx"); }
        lblorderid.Text = od.ORDER_ID;
        lblspje.Text = Decimal.Round(od.ORDER_AMT, 2).ToString();
        lblsl.Text = Decimal.Round(od.ORDER_QTY, 0).ToString();
        lblorderrq.Text = od.ORDER_CREATEDATE.ToString();
        lblorderje.Text = Decimal.Round(od.ORDER_AAMT, 2).ToString();
        lblksrq.Text = od.ORDER_CHECKDATE == DateTime.MinValue ? "" : od.ORDER_CHECKDATE.ToString();
        lblfhrq.Text = od.ORDER_SENDDATE == DateTime.MinValue ? "" : od.ORDER_SENDDATE.ToString();
        lbldeleterq.Text = od.ORDER_DELETEDATE == DateTime.MinValue ? "" : od.ORDER_DELETEDATE.ToString();

        HyperLink1.Text = od.ORDER_AID;
        HyperLink1.NavigateUrl = "OrderDetail.aspx?code=" + od.ORDER_AID.Trim();

        lblzk.Text = od.ORDER_DISC.ToString();

        lblcsrq.Text = od.ORDER_ACHECKDATE == DateTime.MinValue ? "" : od.ORDER_ACHECKDATE.ToString();
        lblclockrq.Text = od.ORDER_LOCKDATE == DateTime.MinValue ? "" : od.ORDER_LOCKDATE.ToString();
        ckbcs.Checked = od.ORDER_ACHECK == 0 ? false : true;
        ckbfh.Checked = od.ORDER_SEND == 0 ? false : true;
        ckbfp.Checked = od.ORDER_NINV == 0 ? false : true;

        txtfptt.Value = od.ORDER_INVTITLE;
        if (ckbfp.Checked)
        {
            txtfptt.Visible = true;
        }
        else
        {
            txtfptt.Visible = false;
        }

        if (ckbfp.Checked) { ScriptManager.RegisterStartupScript(this, this.GetType(), "", "fpfunc();", true); }
        ckbks.Checked = od.ORDER_CHECK == 0 ? false : true;
        ckbsd.Checked = od.ORDER_LOCK == 0 ? false : true;
        ckbzf.Checked = od.ORDER_DELETE == 0 ? false : true;
        txtbz.Text = od.ORDER_NOTE;
        txtrlje.Text = Decimal.Round(od.ORDER_OFFERAMT, 2).ToString();
        txtwlfy.Text = Decimal.Round(od.ORDER_TRANCOST, 2).ToString();
        lblgmr.Text = od.ORDER_CUSTOMERCODE;
        Label2.Text = new BLL.V_CUSTOMER().GetModel(od.ORDER_CUSTOMERCODE).GKMC;
        lblgmr.NavigateUrl = "~/CustomerArchives/CustomerArchiveDetail.aspx?code=" + od.ORDER_CUSTOMERCODE;
        txtshr.Text = od.ORDER_GETER;
        txtshrdh.Text = od.ORDER_GETERPHONE1;

        txtshrdz.Text = (new BLL.Province().GetModel(od.ORDER_PROVINCE).ProName) + (new BLL.City().GetModel(od.ORDER_CITY).CityName) + (new BLL.Area().GetModel(od.ORDER_AREA).AreaName) + od.ORDER_GETADDRESS;
        txtshrsj.Text = od.ORDER_GETERPHONE2;
        txtshryb.Text = od.ORDER_GETPOSTCODE;
        lblWeight.Text = String.Format("{0:0}", od.ORDER_WEIGHT);
        ckbjs.Checked = od.ORDER_CLEAR == 0 ? false : true;
        lblJSJE.Text = Decimal.Round(od.ORDER_CLEARAMT, 2).ToString();

        List<Model.TRANER> traner = new BLL.TRANER().GetAllList(true);
        ddlwlfs.DataSource = traner;
        ddlwlfs.DataTextField = "TRANER_NAME";
        ddlwlfs.DataValueField = "TRANER_CODE";
        ddlwlfs.DataBind();
        ddlwlfs.SelectedValue = od.ORDER_TRANERCODE;

        ddlfyxz.SelectedValue = od.ORDER_COSTNATURE;
        ddljylx.SelectedValue = od.ORDER_APAY.ToString();

        

        List<Model.ORDERFROM> of = new BLL.ORDERFROM().GetAllList(true);
        ddlddly.DataSource = of;
        ddlddly.DataTextField = "OF_NAME";
        ddlddly.DataValueField = "OF_CODE";
        ddlddly.DataBind();
        ddlddly.SelectedValue = od.ORDER_OFCODE;

        chkAssureDeal.Checked = od.ORDER_SECDEAL == 1 ? true : false;

        #region 按钮状态



        if (!ckbsd.Checked)
        {
            ((Button)BUTTONDJ1.Controls[2]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[6]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[8]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[12]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[14]).Enabled = false;
        }
        else
        {
            ((Button)BUTTONDJ1.Controls[0]).Enabled = false;
            div_addproduct.Visible = true;
            editvisable(DataList1, "btnDelete", true);
            div_addproductzf.Visible = true;
            editvisable(DataList2, "btnDelete", true);
        }
        if (!ckbks.Checked)
        {
            ((Button)BUTTONDJ1.Controls[8]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = false;

            //editvisable(DataList2, "btnAudit", false);
        }
        else
        {
            ((Button)BUTTONDJ1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[6]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[8]).Enabled = true;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = true;
            ((Button)BUTTONDJ1.Controls[12]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[14]).Enabled = false;
            div_addproduct.Visible = false;
            editvisable(DataList1, "btnDelete", false);
            div_addproductzf.Visible = false;
            editvisable(DataList2, "btnDelete", false);

            div_zfnewadd.Visible = false;
            div_spnewadd.Visible = false;
            //editvisable(DataList2, "btnAudit", true);
        }
        if (ckbcs.Checked)
        {
            ((Button)BUTTONDJ1.Controls[0]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[6]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[8]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[12]).Enabled = true;
            ((Button)BUTTONDJ1.Controls[14]).Enabled = false;
            div_addproduct.Visible = false;
            editvisable(DataList1, "btnDelete", false);
            div_addproductzf.Visible = false;
            editvisable(DataList2, "btnDelete", false);
            ////editvisable(DataList2, "btnAudit", false);
        }
        else
        {
            ((Button)BUTTONDJ1.Controls[12]).Enabled = false;
        }
        if (ckbfh.Checked)
        {
            ((Button)BUTTONDJ1.Controls[0]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[2]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[6]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[8]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[12]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[14]).Enabled = false;
        }
        if (ckbzf.Checked)
        {
            ((Button)BUTTONDJ1.Controls[0]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[2]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[6]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[8]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[10]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[12]).Enabled = false;
            ((Button)BUTTONDJ1.Controls[14]).Enabled = false;
            div_addproduct.Visible = false;
            editvisable(DataList1, "btnDelete", false);
            div_addproductzf.Visible = false;
            editvisable(DataList2, "btnDelete", false);
            ////editvisable(DataList2, "btnAudit", false);
        }
        btnClear.Visible = od.ORDER_APAY == 1 ? true : false;
        btnClear.Enabled = od.ORDER_CLEAR == 1 ? false : true;
        btnUpdatePayDetail.Enabled = od.ORDER_CLEAR == 1 ? false : true;
        //((Button)BUTTONDJ1.Controls[12]).Enabled = od.ORDER_CLEAR == 1 ? false : true;
        ((Button)BUTTONDJ1.Controls[2]).Enabled = od.ORDER_CLEAR == 1 ? false : true;
        btnNewZF.Enabled = od.ORDER_APAY == 1 ? false : true;
        #endregion
    }
    #endregion

    #region 编辑列显示状态



    private void editvisable(DataList dls, string btn, bool p)
    {
        for (int i = 0; i < dls.Items.Count; i++)
        {
            ((Button)dls.Items[i].FindControl(btn)).Enabled = p;
        }
    }
    #endregion

    #region 订单商品明细
    private void GetData()
    {
        string orderid = Request.QueryString["code"].ToString().Trim();
        DataSet ds = new BLL.ORDERDETAIL().P_Order_GetProductMX(orderid);
        DataList1.DataSource = ds.Tables[0].DefaultView;
        DataList1.DataBind();
        //decimal zweight = 0.00M;

        //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //{
        //    int sl = 0;
        //    sl = Int32.Parse(ds.Tables[0].Rows[i]["OD_QTY"].ToString());
        //    zweight += Decimal.Parse(ds.Tables[0].Rows[i]["OD_WEIGHT"].ToString())*sl;
        //}
        //lblWeight.Text = Decimal.Round(zweight, 2).ToString();
    }
    protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            DataList1.EditItemIndex = e.Item.ItemIndex;
            GetData();
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string spdm = ((Label)e.Item.FindControl("lblspdm")).Text.Trim();
            string color = ((HiddenField)e.Item.FindControl("hdcolor")).Value.Trim();
            string size = ((HiddenField)e.Item.FindControl("hdsize")).Value.Trim();
            DataSet gg1 = new BLL.SHANGPIN().GetSPGG1(spdm);
            DataSet gg2 = new BLL.SHANGPIN().GetSPGG2(spdm);
            DropDownList ddlcolor = (DropDownList)e.Item.FindControl("color");
            DropDownList ddlsize = (DropDownList)e.Item.FindControl("size");
            ddlcolor.DataSource = gg1.Tables[0].DefaultView;
            ddlcolor.DataBind();
            ddlcolor.SelectedValue = color;
            ddlsize.DataSource = gg2.Tables[0].DefaultView;
            ddlsize.DataBind();
            ddlsize.SelectedValue = size;
        }

    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {

        if (e.CommandName == "update")
        {
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            string[] a = e.CommandArgument.ToString().Split('|');
            string color = ((DropDownList)e.Item.FindControl("color")).SelectedValue;
            string size = ((DropDownList)e.Item.FindControl("size")).SelectedValue;
            string sl = ((TextBox)e.Item.FindControl("txtSL")).Text.Trim();
            string zk = ((TextBox)e.Item.FindControl("txtZK")).Text.Trim();
            if (new BLL.ORDERDETAIL().P_Order_UpdateProductMX(a[0], a[1], color, size, Int32.Parse(sl), Decimal.Parse(zk)))
            {
                Share.InsertLog("400101", "00002");
                Response.Redirect("OrderDetail.aspx?code=" + a[0]);
            }
            else
            {
                Share.Alert(Page, "修改失败"); return;
            }
        }
        if (e.CommandName == "delete")
        {
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            string[] a = e.CommandArgument.ToString().Split('|');
            if (new BLL.ORDERDETAIL().P_Order_DeleteProductMX(a[0], a[1]))
            {
                Share.InsertLog("400101", "00002");
                Response.Redirect("OrderDetail.aspx?code=" + a[0]);
            }
            else
            {
                Share.Alert(Page, "删除失败"); return;
            }
        }
        if (e.CommandName == "chanl")
        {
            string[] a = e.CommandArgument.ToString().Split('|');
            Response.Redirect("OrderDetail.aspx?code=" + a[0]);
        }
    }
    #endregion

    #region 订单支付明细
    private void GetZFData()
    {
        string orderid = Request.QueryString["code"].ToString().Trim();
        DataSet ds = new BLL.PAYDETAIL().P_Order_GetProductZFMX(orderid);
        DataList2.DataSource = ds.Tables[0].DefaultView;
        DataList2.DataBind();
        decimal zfzje = 0.00M;
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            zfzje += Decimal.Parse(ds.Tables[0].Rows[i]["PD_PAYAMT"].ToString());
        }
        lblzfzje.Text = Decimal.Round(zfzje, 2).ToString();
    }
    protected void DataList2_EditCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            DataList2.EditItemIndex = e.Item.ItemIndex;
            GetZFData();
        }
    }
    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string jylx = ((HiddenField)e.Item.FindControl("HiddenField1")).Value.Trim();
            ((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue = jylx;
            string zfdm = ((HiddenField)e.Item.FindControl("hid_zfdm")).Value.Trim();
            DataSet pt = new BLL.PAYTYPE_DEALTYPE().P_DealType_GetPayTypeByCode(jylx);
            DropDownList ddl = (DropDownList)e.Item.FindControl("ddlzflx");

            ListItem tempItem;

            for (int i = 0; i < pt.Tables[0].Rows.Count; i++)
            {
                tempItem = new ListItem();
                tempItem.Text = pt.Tables[0].Rows[i]["PT_NAME"].ToString();
                tempItem.Value = pt.Tables[0].Rows[i]["PT_CODE"].ToString() + "|" + pt.Tables[0].Rows[i]["PT_HAVEDEAL"].ToString();
                ddl.Items.Add(tempItem);
            }
            for (int i = 0; i < ddl.Items.Count; i++)
            {
                string[] value = ddl.Items[i].Value.Split('|');
                if (value[0] == zfdm)
                {
                    ddl.SelectedIndex = i;
                }
            }


        }

    }
    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {

        if (e.CommandName == "update")
        {
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            string orderid = Request.QueryString["code"].ToString().Trim();
            string detailid = e.CommandArgument.ToString().Trim();
            string zfdm = ((DropDownList)e.Item.FindControl("ddlzflx")).SelectedValue;
            string zfje = ((TextBox)e.Item.FindControl("txtzfje")).Text.Trim();
            string zfrq = ((TextBox)e.Item.FindControl("txtzfrq")).Text.Trim();
            string jyh = ((TextBox)e.Item.FindControl("txtjyh")).Text.Trim();
            string jyrq = ((TextBox)e.Item.FindControl("txtjyrq")).Text.Trim();
            string bz = ((TextBox)e.Item.FindControl("txtbz")).Text.Trim();
            string zhanghao = ((TextBox)e.Item.FindControl("txtzhanghao")).Text.Trim();
            if (new BLL.PAYDETAIL().P_Order_UpdateProductZFMX(orderid, detailid, zfdm, Decimal.Parse(zfje), zfrq == "" ? DateTime.MinValue : DateTime.Parse(zfrq), jyh, jyrq == "" ? DateTime.MinValue : DateTime.Parse(jyrq), zhanghao, bz))
            {
                Share.InsertLog("400101", "00002");
                Response.Redirect("OrderDetail.aspx?code=" + orderid);
            }
            else
            {
                Share.Alert(Page, "修改失败"); return;
            }
        }
        if (e.CommandName == "audit")
        {
            string orderid = Request.QueryString["code"].ToString().Trim();
            if (!Check.CheckPermission("400101", "00013"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            Model.PAYDETAIL pd = new BLL.PAYDETAIL().GetModel(orderid, e.CommandArgument.ToString());
            pd.PD_CHECK = 1;
            pd.PD_CHECKDATE = DateTime.Now;
            pd.PD_CHECKER = Share.UserValue(0);

            if (new BLL.PAYDETAIL().Update(pd))
            {
                Share.InsertLog("400101", "00013");
                Response.Redirect("OrderDetail.aspx?code=" + orderid);
            }
            else
            {
                Share.Alert(Page, "删除失败"); return;
            }
        }
        if (e.CommandName == "delete")
        {
            string orderid = Request.QueryString["code"].ToString().Trim();
            if (!Check.CheckPermission("400101", "00002"))
            {
                Share.Alert(this.Page, "无权操作"); return;
            }
            if (new BLL.PAYDETAIL().P_Order_DeleteProductZFMX(orderid, e.CommandArgument.ToString()))
            {
                Share.InsertLog("400101", "00002");
                Response.Redirect("OrderDetail.aspx?code=" + orderid);
            }
            else
            {
                Share.Alert(Page, "删除失败"); return;
            }
        }
        if (e.CommandName == "chanl")
        {
            string orderid = Request.QueryString["code"].ToString().Trim();
            Response.Redirect("OrderDetail.aspx?code=" + orderid);
        }
    }

    protected void DataList2_DDLCHANGE_Click(object sender, EventArgs e)
    {
        DropDownList c = (DropDownList)sender;
        DataSet dst = new BLL.PAYTYPE_DEALTYPE().P_DealType_GetPayTypeByCode(c.SelectedValue);
        ListItem tempItem;
        DropDownList ss = c.Parent.FindControl("ddlzflx") as DropDownList;
        ss.Items.Clear();
        for (int i = 0; i < dst.Tables[0].Rows.Count; i++)
        {
            tempItem = new ListItem();
            tempItem.Text = dst.Tables[0].Rows[i]["PT_NAME"].ToString();
            tempItem.Value = dst.Tables[0].Rows[i]["PT_CODE"].ToString() + "|" + dst.Tables[0].Rows[i]["PT_HAVEDEAL"].ToString();
            ss.Items.Add(tempItem);
        }
    }
    #endregion

    #region 添加商品
    public void RaiseCallbackEvent(string eventArgument)
    {
        //try
        //{
        //    if (!Check.CheckPermission("400101", "00002"))
        //    {
        //        result = "s";
        //    }
        //    else
        //    {
        //        string order_id = Request.QueryString["code"].ToString();
        //        string[] content = eventArgument.Split('|');
        //        ERP.ORDERDOC od = new ERP.ORDERDOC();
        //            od.ORDER_OFFERAMT = txtrlje.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtrlje.Text.Trim());
        //            od.ORDER_TRANCOST = txtwlfy.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtwlfy.Text.Trim());
        //            od.ORDER_NINV = ckbfp.Checked == true ? 1 : 0;
        //            od.ORDER_NOTE = txtbz.Text.Trim();
        //            od.ORDER_GETER = txtshr.Text.Trim();
        //            od.ORDER_GETERPHONE1 = txtshrdh.Text.Trim();
        //            od.ORDER_GETERPHONE2 = txtshrsj.Text.Trim();
        //            od.ORDER_GETPOSTCODE = txtshryb.Text.Trim();
        //            od.ORDER_GETADDRESS = txtshrdz.Text.Trim();
        //            od.ORDER_TRANERCODE = ddlwlfs.SelectedValue;
        //            od.ORDER_COSTNATURE = ddlfyxz.SelectedValue;
        //            od.ORDER_DTCODE = ddljylx.SelectedValue;
        //            od.ORDER_OFCODE = ddlddly.SelectedValue;
        //            for (int g = 0; g < DataList1.Items.Count; g++)
        //            {
        //                string spdm = ((Label)DataList1.Items[g].FindControl("lblspdm")).Text.Trim();
        //                string color = ((DropDownList)DataList1.Items[g].FindControl("color")).SelectedValue;
        //                string size = ((DropDownList)DataList1.Items[g].FindControl("size")).SelectedValue;
        //                string sl = ((TextBox)DataList1.Items[g].FindControl("txtSL")).Text.Trim();
        //                string zk = ((TextBox)DataList1.Items[g].FindControl("txtZK")).Text.Trim();
        //                content[0] += spdm + "," + color + "," + size + "," + sl + "," + zk + "#";
        //            }
        //            for (int f = 0; f < DataList2.Items.Count; f++)
        //            {
        //                string zfdm = ((DropDownList)DataList2.Items[f].FindControl("ddlzflx")).SelectedValue;
        //                string zfje = ((TextBox)DataList2.Items[f].FindControl("txtzfje")).Text.Trim();
        //                string zfrq = ((TextBox)DataList2.Items[f].FindControl("txtzfrq")).Text.Trim();
        //                string jyh = ((TextBox)DataList2.Items[f].FindControl("txtjyh")).Text.Trim();
        //                string jyrq = ((TextBox)DataList2.Items[f].FindControl("txtjyrq")).Text.Trim();
        //                string bz = ((TextBox)DataList2.Items[f].FindControl("txtbz")).Text.Trim();
        //                string zhanghao = ((TextBox)DataList2.Items[f].FindControl("txtzhanghao")).Text.Trim();
        //                content[1] += zhanghao + "," + zfdm + "," + zfje + "," + zfrq + "," + jyh + "," + jyrq + "," + bz + "#";
        //            }
        //            if (content[0].Trim() != "")
        //            {
        //                content[0] = content[0].Length > 1 ? content[0].Substring(0, content[0].Length - 1) : "";
        //            }
        //            if (content[1].Trim() != "")
        //            {
        //                content[1] = content[1].Length > 1 ? content[1].Substring(0, content[1].Length - 1) : "";
        //            }
        //            ERP.Service erpservice = new ERP.Service();
        //            int re = erpservice.P_Order_Update("baison", Request.QueryString["code"].ToString(), content[0], content[1], od);
        //            result = re.ToString();
        //        Share.InsertLog("400101", "00002");

        //    }
        //}
        //catch
        //{
        //    result = "catch";
        //}
    }

    public string GetCallbackResult()
    {
        return result == "0" ? Request.QueryString["code"].ToString().Trim() : "";
        //return result;
    }

    //private string sss()
    //{


    //}
    #endregion

    #region 按钮操作

    #region 锁定

    public void Lock()
    {
        if (!Check.CheckPermission("400101", "00008"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString());
        od.ORDER_LOCK = 1;
        od.ORDER_LOCKER = Share.UserValue(0);
        od.ORDER_LOCKDATE = DateTime.Now;
        if (new BLL.ORDERDOC().Update(od))
        {
            Share.InsertLog("400101", "00008");
            Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim());
            //ContextUtil.SetComplete();
        }
        else
        {
            //ContextUtil.SetAbort();
            Share.Alert(Page, "锁定失败"); return;
        }
    }
    #endregion

    #region 解锁
    public void UnLock()
    {
        if (!Check.CheckPermission("400101", "00009"))
        {
            Share.Alert(Page, "无权操作"); return;
        }
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString());
        od.ORDER_LOCK = 0;
        od.ORDER_UPLOCKER = Share.UserValue(0);
        od.ORDER_UPLOCKDATE = DateTime.Now;
        if (new BLL.ORDERDOC().Update(od))
        {
            Share.InsertLog("400101", "00009");
            Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim());
        }
        else
        {
            Share.Alert(Page, "解锁失败"); return;
        }
    }
    #endregion

    #region 保存
    public void Save()
    {
        if (!Check.CheckPermission("400101", "00017"))
        {

        }
        try
        {
            if ((DataList1.Items.Count + tab_sp.Rows.Count) == 0)
            {
                Share.Alert(Page, "请输入所购商品！"); return;
            }
            //if (txtshrdh.Text.Trim() == "" && txtshrsj.Text.Trim() == "")
            //{
            //    Share.Alert(Page, "“收货人固定电话”、“收货人手机”至少有一个不能为空！");
            //}
            string eventArgument = "|";
            string order_id = Request.QueryString["code"].ToString();
            string[] content = eventArgument.Split('|');
            LX_Manage.ERP.ORDERDOC od = new LX_Manage.ERP.ORDERDOC();
            od.ORDER_OFFERAMT = txtrlje.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtrlje.Text.Trim());
            od.ORDER_TRANCOST = txtwlfy.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtwlfy.Text.Trim());
            od.ORDER_NINV = ckbfp.Checked == true ? 1 : 0;
            od.ORDER_NOTE = txtbz.Text.Trim();
            od.ORDER_GETER = txtshr.Text.Trim();
            od.ORDER_GETERPHONE1 = txtshrdh.Text.Trim();
            od.ORDER_GETERPHONE2 = txtshrsj.Text.Trim();

            od.ORDER_GETPOSTCODE = txtshryb.Text.Trim();
            od.ORDER_GETADDRESS = txtshrdz.Text.Trim();
            od.ORDER_TRANERCODE = ddlwlfs.SelectedValue;
            od.ORDER_COSTNATURE = ddlfyxz.SelectedValue;
            od.ORDER_DTCODE = ddljylx.SelectedValue;
            od.ORDER_OFCODE = ddlddly.SelectedValue;
            od.ORDER_WEIGHT = Decimal.Parse(lblWeight.Text.Trim());
            od.ORDER_INVTITLE = txtfptt.Value.Trim();
            for (int g = 0; g < DataList1.Items.Count; g++)
            {
                string spdm = ((Label)DataList1.Items[g].FindControl("lblspdm")).Text.Trim();
                string color = ((DropDownList)DataList1.Items[g].FindControl("color")).SelectedValue;
                string size = ((DropDownList)DataList1.Items[g].FindControl("size")).SelectedValue;
                string sl = ((TextBox)DataList1.Items[g].FindControl("txtSL")).Text.Trim();
                string zk = ((TextBox)DataList1.Items[g].FindControl("txtZK")).Text.Trim();
                content[0] += spdm + "," + color + "," + size + "," + sl + "," + zk + "#";
            }
            for (int o = 0; o < tab_sp.Rows.Count; o++)
            {
                string spdm = ((Label)tab_sp.Rows[o].Cells[1].Controls[0]).ToolTip;
                string color = ((DropDownList)tab_sp.Rows[o].Cells[2].Controls[0]).SelectedValue;
                string size = ((DropDownList)tab_sp.Rows[o].Cells[3].Controls[0]).SelectedValue;
                string sl = ((TextBox)tab_sp.Rows[o].Cells[4].Controls[0]).Text.Trim();
                string zk = ((TextBox)tab_sp.Rows[o].Cells[6].Controls[0]).Text.Trim();
                content[0] += spdm + "," + color + "," + size + "," + sl + "," + zk + "#";
            }
            for (int f = 0; f < DataList2.Items.Count; f++)
            {
                string selectValue = ((DropDownList)DataList2.Items[f].FindControl("ddlzflx")).SelectedValue;
                string zfje = ((TextBox)DataList2.Items[f].FindControl("txtzfje")).Text.Trim();
                string zfrq = ((DropDownList)DataList2.Items[f].FindControl("DropDownList1")).Text.Trim();
                string jyh = ((TextBox)DataList2.Items[f].FindControl("txtjyh")).Text.Trim();
                string jyrq = ((TextBox)DataList2.Items[f].FindControl("txtjyrq")).Text.Trim();
                string bz = ((TextBox)DataList2.Items[f].FindControl("txtbz")).Text.Trim();
                string zhanghao = ((TextBox)DataList2.Items[f].FindControl("txtzhanghao")).Text.Trim();

                od.ORDER_PAYAMT += Convert.ToDecimal(zfje);

                string[] value = selectValue.Split('|');
                //if (value[1] == "1" && jyh == "")
                //{
                //    Share.Alert(Page, "您选择的支付方式必须输入交易号，请输入！"); return;
                //}

                content[1] += zhanghao + "," + value[0] + "," + zfje + "," + zfrq + "," + jyh + "," + jyrq + "," + bz + "#";
                if (zfje.Trim() == "" || jyrq.Trim() == "" || zhanghao.Trim() == "")
                {
                    Share.Alert(Page, "请录入支付明细数据！"); return;
                }
            }
            for (int p = 0; p < tab_zf.Rows.Count; p++)
            {
                string zfrq = ((DropDownList)tab_zf.Rows[p].Cells[2].Controls[0]).SelectedValue;
                string selectValue = ((DropDownList)tab_zf.Rows[p].Cells[3].Controls[0]).SelectedValue;
                string zfje = ((TextBox)tab_zf.Rows[p].Cells[4].Controls[0]).Text.Trim();

                string jyh = ((TextBox)tab_zf.Rows[p].Cells[5].Controls[0]).Text.Trim();
                string jyrq = ((TextBox)tab_zf.Rows[p].Cells[6].Controls[0]).Text.Trim();
                string bz = ((TextBox)tab_zf.Rows[p].Cells[7].Controls[0]).Text.Trim();
                string zhanghao = ((TextBox)tab_zf.Rows[p].Cells[1].Controls[0]).Text.Trim();

                string[] value = selectValue.Split('|');
                if (value[1] == "1" && jyh == "")
                {
                    Share.Alert(Page, "您选择的支付方式必须输入交易号，请输入！"); return;
                }

                content[1] += zhanghao + "," + value[0] + "," + zfje + "," + zfrq + "," + jyh + "," + jyrq + "," + bz + "#";
                if (zfje.Trim() == "" || zfrq.Trim() == "" || jyrq.Trim() == "" || zhanghao.Trim() == "")
                {
                    Share.Alert(Page, "请录入支付明细数据！"); return;
                }
                od.ORDER_PAYAMT += Convert.ToDecimal(zfje);
            }
            if (content[0].Trim() != "")
            {
                content[0] = content[0].Length > 1 ? content[0].Substring(0, content[0].Length - 1) : "";
            }
            if (content[1].Trim() != "")
            {
                content[1] = content[1].Length > 1 ? content[1].Substring(0, content[1].Length - 1) : "";
            }

            LX_Manage.ERP.Service erpservice = new LX_Manage.ERP.Service();
            string key = ConfigurationManager.AppSettings["CODE"];
            int re = erpservice.P_Order_Update(key, Request.QueryString["code"].ToString(), content[0], content[1], od);
            result = re.ToString();
            Share.InsertLog("400101", "00017");

            Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim(), false);
        }
        catch
        {

        }
        //try
        //{
        //    if (!Check.CheckPermission("400101", "00002"))
        //    {
        //        return false;
        //    }
        //    Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString());
        //    od.ORDER_OFFERAMT = txtrlje.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtrlje.Text.Trim());
        //    od.ORDER_TRANCOST = txtwlfy.Text.Trim() == "" ? 0.00M : Decimal.Parse(txtwlfy.Text.Trim());
        //    od.ORDER_NINV = ckbfp.Checked == true ? 1 : 0;
        //    od.ORDER_NOTE = txtbz.Text.Trim();
        //    od.ORDER_GETER = txtshr.Text.Trim();
        //    od.ORDER_GETERPHONE1 = txtshrdh.Text.Trim();
        //    od.ORDER_GETERPHONE2 = txtshrsj.Text.Trim();
        //    od.ORDER_GETPOSTCODE = txtshryb.Text.Trim();
        //    od.ORDER_GETADDRESS = txtshrdz.Text.Trim();
        //    od.ORDER_TRANERCODE = ddlwlfs.SelectedValue;
        //    od.ORDER_COSTNATURE = ddlfyxz.SelectedValue;
        //    od.ORDER_DTCODE = ddljylx.SelectedValue;
        //    od.ORDER_OFCODE = ddlddly.SelectedValue;
        //    if (new BLL.ORDERDOC().Update(od))
        //    {
        //        string orderid = Request.QueryString["code"].ToString().Trim();
        //        for (int g = 0; g < DataList1.Items.Count; g++)
        //        {
        //            string spdm = ((Label)DataList1.Items[g].FindControl("lblspdm")).Text.Trim();
        //            string color = ((DropDownList)DataList1.Items[g].FindControl("color")).SelectedValue;
        //            string size = ((DropDownList)DataList1.Items[g].FindControl("size")).SelectedValue;
        //            string sl = ((TextBox)DataList1.Items[g].FindControl("txtSL")).Text.Trim();
        //            string zk = ((TextBox)DataList1.Items[g].FindControl("txtZK")).Text.Trim();
        //            if (new BLL.ORDERDETAIL().P_Order_InsertProductMX(orderid, spdm, color, size, sl == "" ? 0 : Int32.Parse(sl), zk == "" ? 0 : Decimal.Parse(zk)))
        //            {
        //                return false;
        //            }
        //        }
        //        for (int f = 0; f < DataList2.Items.Count; f++)
        //        {
        //            string zfdm = ((DropDownList)DataList2.Items[f].FindControl("ddlzflx")).SelectedValue;
        //            string zfje = ((TextBox)DataList2.Items[f].FindControl("txtzfje")).Text.Trim();
        //            string zfrq = ((TextBox)DataList2.Items[f].FindControl("txtzfrq")).Text.Trim();
        //            string jyh = ((TextBox)DataList2.Items[f].FindControl("txtjyh")).Text.Trim();
        //            string jyrq = ((TextBox)DataList2.Items[f].FindControl("txtjyrq")).Text.Trim();
        //            string bz = ((TextBox)DataList2.Items[f].FindControl("txtbz")).Text.Trim();
        //            string zhanghao = ((TextBox)DataList2.Items[f].FindControl("txtzhanghao")).Text.Trim();
        //            if (new BLL.PAYDETAIL().Add(orderid, zfdm, zfje == "" ? 0.00M : Decimal.Parse(zfje), zfrq == "" ? DateTime.MinValue : DateTime.Parse(zfrq), jyh, jyrq == "" ? DateTime.MinValue : DateTime.Parse(jyrq), zhanghao, bz) == null)
        //            {
        //                return false;
        //            }
        //        }
        //        return true;
        //        //Share.InsertLog("400101", "00002");
        //        //Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim());
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        //catch
        //{
        //    return false;
        //}
    }
    #endregion

    #region 审批
    public void Audit()
    {

        if (!Check.CheckPermission("400101", "00010"))
        {
            Share.Alert(Page, "无权操作"); return;
        }

        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString().Trim());
        if (od.ORDER_GETERPHONE1.Trim() == "" && od.ORDER_GETERPHONE2.Trim() == "")
        {
            Share.Alert(Page, "“收货人固定电话”、“收货人手机”至少有一个不能为空！"); return;
        }
        //if (od.ORDER_DTCODE == "001" || od.ORDER_DTCODE == "002")
        //{
        //    if (DataList2.Items.Count == 0)
        //    {
        //        Share.Alert(Page, "请填写支付明细！"); return;
        //    }
        //}
        bool kykc = true;
        //校验可用库存
        for (int g = 0; g < DataList1.Items.Count; g++)
        {
            string spdm = ((Label)DataList1.Items[g].FindControl("lblspdm")).Text.Trim();
            string color = ((DropDownList)DataList1.Items[g].FindControl("color")).SelectedValue;
            string size = ((DropDownList)DataList1.Items[g].FindControl("size")).SelectedValue;
            string sl = ((TextBox)DataList1.Items[g].FindControl("txtSL")).Text.Trim();
            
            string spzs = new BLL.SPKCB().OC_Product_KEYONG_Stocks("spkcb.spdm='" + spdm + "' and gg1dm='" + color + "' and gg2dm='" + size + "' ");
            if (Decimal.Parse(sl) > Decimal.Parse(spzs))
            {
                kykc = false; break;
            }
        }
        if (ckbfp.Checked)
        {
            if (txtfptt.Value == "")
            {
                Share.Alert(Page, "请填写发票抬头！");
                return;
            }
        }

        if (!kykc)
        {
            this.programmaticModalPopup.Show(); return;
        }
        
        if (od.ORDER_APAY == 0)
        {
            if (Decimal.Parse(lblorderje.Text.Trim()) > Decimal.Parse(lblzfzje.Text.Trim()))
            {
                Share.Alert(Page, "支付金额不足"); return;
            }
            decimal jyk_zfje = 0.00M;
            for (int f = 0; f < DataList2.Items.Count; f++)
            {
                string selectValue = ((DropDownList)DataList2.Items[f].FindControl("ddlzflx")).SelectedValue;
                string zfje = ((TextBox)DataList2.Items[f].FindControl("txtzfje")).Text.Trim();
                string zfrq = ((DropDownList)DataList2.Items[f].FindControl("DropDownList1")).Text.Trim();
                string jyh = ((TextBox)DataList2.Items[f].FindControl("txtjyh")).Text.Trim();
                string jyrq = ((TextBox)DataList2.Items[f].FindControl("txtjyrq")).Text.Trim();
                string bz = ((TextBox)DataList2.Items[f].FindControl("txtbz")).Text.Trim();
                string zhanghao = ((TextBox)DataList2.Items[f].FindControl("txtzhanghao")).Text.Trim();

                string[] value = selectValue.Split('|');

                if (value[1] == "1")
                {
                    if (jyh == "")
                    {
                        Share.Alert(Page, "请输入交易号！"); return;
                    }
                    DataSet dst = new BLL.PAYDETAIL().GetPayDetailByPayTypeAndDealId(value[0], jyh);
                    if (dst.Tables[0].Rows.Count > 1)
                    {
                        string strInfo = "交易号为" + jyh + "的支付明细与其他订单的支付明细交易号重复，请核对交易号重新输入后保存订单，并再次审核！";
                        Share.Alert(Page, strInfo); return;
                    }
                }

                
                if (zfrq == "003")
                {
                    jyk_zfje += decimal.Parse(zfje);
                }
            }
            if (jyk_zfje > 0.00M)
            {
                Model.V_VIPSET vvs = new BLL.V_VIPSET().GetModelByGKDM(od.ORDER_CUSTOMERCODE);
                Model.V_VIP_ACCOUNT vva = new BLL.V_VIP_ACCOUNT().GetModel(vvs.DM);
                if (vva == null)
                {
                    if (0.00M + vvs.BYZD12 < jyk_zfje)
                    {
                        Share.Alert(Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
                    }
                }
                else
                {
                    if (vva.DQJE_1 + vvs.BYZD12 < jyk_zfje)
                    {
                        Share.Alert(Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
                    }
                }

            }
        }
        if (new BLL.ORDERDOC().P_Order_Audit(0, System.Configuration.ConfigurationSettings.AppSettings["ckdm"].ToString(), System.Configuration.ConfigurationSettings.AppSettings["kwdm"].ToString(), Request.QueryString["code"].ToString().Trim(), Share.UserValue(0)))
        {
            Share.InsertLog("400101", "00010");
            //if (od.ORDER_APAY == 1)
            //{
            //    CAudit();
            //}
            Response.Redirect("OrderDetail.aspx?p=1&code=" + Request.QueryString["code"].ToString().Trim());
        }
        else
        {
            Share.Alert(Page, "审批失败"); return;
        }
    }
    #endregion

    #region 反审批



    public void UnAudit()
    {
        if (!Check.CheckPermission("400101", "00011"))
        {
            Share.Alert(Page, "无权操作"); return;
        }
        if (new BLL.ORDERDOC().P_Order_Audit(1, System.Configuration.ConfigurationSettings.AppSettings["ckdm"].ToString(), System.Configuration.ConfigurationSettings.AppSettings["kwdm"].ToString(), Request.QueryString["code"].ToString().Trim(), Share.UserValue(0)))
        {
            Share.InsertLog("400101", "00011");
            Response.Redirect("OrderDetail.aspx?p=1&code=" + Request.QueryString["code"].ToString().Trim());
        }
        else
        {
            Share.Alert(Page, "反审批失败"); return;
        }
    }
    #endregion

    #region 作废
    public void Delete()
    {
        if (!Check.CheckPermission("400101", "00003"))
        {
            Share.Alert(Page, "无权操作"); return;
        }
        if (txtbz.Text.Trim() == "")
        {
            Share.Alert(Page, "请写备注"); return;
        }
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString());
        od.ORDER_DELETE = 1;
        od.ORDER_DELETER = Share.UserValue(0);
        od.ORDER_DELETEDATE = DateTime.Now;
        if (new BLL.ORDERDOC().Update(od))
        {
            Share.InsertLog("400101", "00003");
            Response.Redirect("OrderList.aspx");
        }
        else
        {
            Share.Alert(Page, "保存失败"); return;
        }
    }
    #endregion


    #region 财务审批
    public void CAudit()
    {
        //if (!Check.CheckPermission("400101", "00012"))
        //{
        //    Share.Alert(Page, "无权操作"); return;
        //}

        //bool result = false;

        //Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString().Trim());//获取订单主表

        //switch (order.ORDER_APAY.ToString())
        //{
        //    case "0"://非货到付款

        //        if (Decimal.Parse(lblorderje.Text.Trim()) <= Decimal.Parse(lblzfzje.Text.Trim()))
        //        {
        //            DataSet ds = new BLL.PAYDETAIL().P_Order_GetProductZFMX(Request.QueryString["code"].ToString().Trim());//获取订单支付明细

        //            #region 含担保交易

        //            if (order.ORDER_SECDEAL == 1)
        //            {
        //                decimal immediatePayAmount = 0.00M;
        //                decimal accountPayAmount = 0.00M;
        //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
        //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

        //                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //                {
        //                    if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "001")
        //                    {
        //                        immediatePayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "003")
        //                    {
        //                        accountPayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else
        //                    {
        //                        continue;
        //                    }
        //                    strSqlToUpdateBStyleDB.Append("update paydetail set PD_GET=1,PD_GETAMT=");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    strSqlToUpdateBStyleDB.Append(" where PD_ID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_ID"]);
        //                    strSqlToUpdateBStyleDB.Append("' and PD_DETAILID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_DETAILID"]);
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                string operatorId = Share.UserValue(0);

        //                if (order.ORDER_PAYAMT <= immediatePayAmount + accountPayAmount)
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=1,ORDER_ACHECKER='");
        //                    strSqlToUpdateBStyleDB.Append(operatorId);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEAR=1,ORDER_CLEARAMT=ORDER_CLEARAMT+");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }
        //                else
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=1,ORDER_ACHECKER='");
        //                    strSqlToUpdateBStyleDB.Append(operatorId);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEARAMT=ORDER_CLEARAMT+");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
        //                if (userInfo == null)
        //                {
        //                    Share.Alert(Page, "系统内无此会员信息！"); return;
        //                }
        //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

        //                if (userAccount == null)
        //                {
        //                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
        //                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append("',0)|");

        //                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
        //                    strSqlToUpdateErpDB.Append(userInfo.DM);
        //                    strSqlToUpdateErpDB.Append("',0)|");
        //                }
        //                if (accountPayAmount != 0)
        //                {
        //                    if (accountPayAmount > userInfo.BYZD12 + userAccount.DQJE_1)
        //                    {
        //                        Share.Alert(this.Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
        //                    }

                            
        //                    string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(accountPayAmount * -1, userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
        //                    strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

        //                    string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("003", operatorId, operatorId, order.ORDER_CUSTOMERCODE, accountPayAmount * -1);
        //                    strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);
                            
        //                }

        //                if (strSqlToUpdateErpDB.ToString() == "")
        //                {
        //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
        //                    result = new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
        //                }
        //                else
        //                {
        //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
        //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
        //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

        //                    ERP.Service webService = new ERP.Service();
        //                    result = webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
        //                }
        //            }
        //            #endregion
        //            #region 不含担保交易
        //            else
        //            {
        //                decimal immediatePayAmount = 0.00M;
        //                decimal accountPayAmount = 0.00M;
        //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
        //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

        //                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //                {
        //                    if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "001")
        //                    {
        //                        immediatePayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "003")
        //                    {
        //                        accountPayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else
        //                    {
        //                        continue;
        //                    }
        //                    strSqlToUpdateBStyleDB.Append("update paydetail set PD_GET=1,PD_GETAMT=");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    strSqlToUpdateBStyleDB.Append(" where PD_ID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_ID"]);
        //                    strSqlToUpdateBStyleDB.Append("' and PD_DETAILID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_DETAILID"]);
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                string operatorId = Share.UserValue(0);

        //                if (order.ORDER_PAYAMT <= immediatePayAmount + accountPayAmount)
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=1,ORDER_ACHECKER='");
        //                    strSqlToUpdateBStyleDB.Append(operatorId);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEAR=1,ORDER_CLEARAMT=ORDER_CLEARAMT+");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }
        //                else
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=1,ORDER_ACHECKER='");
        //                    strSqlToUpdateBStyleDB.Append(operatorId);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEARAMT=ORDER_CLEARAMT+");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
        //                if (userInfo == null)
        //                {
        //                    Share.Alert(Page, "系统内无此会员信息！"); return;
        //                }
        //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

        //                if (userAccount == null)
        //                {
        //                    strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
        //                    strSqlToUpdateBStyleDB.Append(userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append("',0)|");

        //                    strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
        //                    strSqlToUpdateErpDB.Append(userInfo.DM);
        //                    strSqlToUpdateErpDB.Append("',0)|");
        //                }
        //                if (accountPayAmount != 0)
        //                {
        //                    if (accountPayAmount > userInfo.BYZD12 + userAccount.DQJE_1)
        //                    {
        //                        Share.Alert(this.Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
        //                    }

                            
        //                    string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(accountPayAmount * -1, userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
        //                    strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

        //                    string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("003", operatorId, operatorId, order.ORDER_CUSTOMERCODE, accountPayAmount * -1);
        //                    strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);
                            
        //                }

        //                if (strSqlToUpdateErpDB.ToString() == "")
        //                {
        //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
        //                    result = new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
        //                }
        //                else
        //                {
        //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
        //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
        //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

        //                    ERP.Service webService = new ERP.Service();
        //                    result = webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
        //                }
        //            }
        //            #endregion                   
        //        }
        //        else
        //        {
        //            Share.Alert(Page, "支付金额不足"); return;
        //        }
        //        break;

        //    case "1":
        //        order.ORDER_ACHECK = 1;
        //        order.ORDER_ACHECKER = Share.UserValue(0);
        //        order.ORDER_ACHECKDATE = DateTime.Now;

        //        result = new BLL.ORDERDOC().Update(order);
        //        break;
        //}
        //if (result)
        //{
        //    Share.InsertLog("400101", "00012");
        //    Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim());
        //}
        //else
        //{
        //    Share.Alert(Page, "财务审核失败"); return;
        //}

    }
    #endregion

    #region 财务反审批



    public void UnCAudit()
    {

        //if (!Check.CheckPermission("400101", "00013"))
        //{
        //    Share.Alert(Page, "无权操作"); return;
        //}

        //bool result = false;

        //Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString().Trim());//获取订单主表

        //switch (order.ORDER_APAY.ToString())
        //{
        //    case "0"://即时到帐--2结算单审批修改结余款、3订单财务审批
        //        if (Decimal.Parse(lblorderje.Text.Trim()) <= Decimal.Parse(lblzfzje.Text.Trim()))
        //        {
        //            DataSet ds = new BLL.PAYDETAIL().P_Order_GetProductZFMX(Request.QueryString["code"].ToString().Trim());//获取订单支付明细

        //            #region 含担保交易

        //            if (order.ORDER_SECDEAL == 1)
        //            {
        //                decimal immediatePayAmount = 0.00M;
        //                decimal accountPayAmount = 0.00M;
        //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
        //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

        //                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //                {
        //                    if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "001")
        //                    {
        //                        immediatePayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "003")
        //                    {
        //                        accountPayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else
        //                    {
        //                        continue;
        //                    }
        //                    strSqlToUpdateBStyleDB.Append("update paydetail set PD_GET=0,PD_GETAMT=0 where PD_ID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_ID"]);
        //                    strSqlToUpdateBStyleDB.Append("' and PD_DETAILID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_DETAILID"]);
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                string operatorId = Share.UserValue(0);

        //                if (order.ORDER_PAYAMT > immediatePayAmount + accountPayAmount)
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=0,ORDER_ACHECKER='',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEAR=0,ORDER_CLEARAMT=ORDER_CLEARAMT-");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }
        //                else
        //                {
        //                    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=0,ORDER_ACHECKER='',ORDER_ACHECKDATE='");
        //                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                    strSqlToUpdateBStyleDB.Append("',ORDER_CLEARAMT=ORDER_CLEARAMT-");
        //                    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
        //                if (userInfo == null)
        //                {
        //                    Share.Alert(Page, "系统内无此会员信息！"); return;
        //                }
        //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

        //                if (userAccount == null)
        //                {
        //                    Share.Alert(this.Page, "系统内无此会员的结余款信息，因此不能使用结余款支付！"); return;
        //                }
        //                if (accountPayAmount != 0)
        //                {
        //                    if (accountPayAmount > userInfo.BYZD12 + userAccount.DQJE_1)
        //                    {
        //                        Share.Alert(this.Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
        //                    }

                            
        //                    string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(accountPayAmount, userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
        //                    strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

        //                    string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("004", operatorId, operatorId, order.ORDER_CUSTOMERCODE, accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);
                            
        //                }

        //                if (strSqlToUpdateErpDB.ToString() == "")
        //                {
        //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
        //                    result = new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
        //                }
        //                else
        //                {
        //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
        //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
        //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

        //                    ERP.Service webService = new ERP.Service();
        //                    result = webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
        //                }
        //            }
        //            #endregion
        //            #region 不含担保交易
        //            else
        //            {
        //                decimal immediatePayAmount = 0.00M;
        //                decimal accountPayAmount = 0.00M;
        //                StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
        //                StringBuilder strSqlToUpdateErpDB = new StringBuilder();

        //                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //                {
        //                    if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "001")
        //                    {
        //                        immediatePayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else if (ds.Tables[0].Rows[i]["PD_DTCODE"].ToString() == "003")
        //                    {
        //                        accountPayAmount += Convert.ToDecimal(ds.Tables[0].Rows[i]["PD_PAYAMT"]);
        //                    }
        //                    else
        //                    {
        //                        continue;
        //                    }
        //                    strSqlToUpdateBStyleDB.Append("update paydetail set PD_GET=0,PD_GETAMT=0 where PD_ID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_ID"]);
        //                    strSqlToUpdateBStyleDB.Append("' and PD_DETAILID='");
        //                    strSqlToUpdateBStyleDB.Append(ds.Tables[0].Rows[i]["PD_DETAILID"]);
        //                    strSqlToUpdateBStyleDB.Append("'|");
        //                }

        //                string operatorId = Share.UserValue(0);

        //                //if (order.ORDER_PAYAMT > immediatePayAmount + accountPayAmount)
        //                //{
        //                //    strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=0,ORDER_ACHECKER='',ORDER_ACHECKDATE='");
        //                //    strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                //    strSqlToUpdateBStyleDB.Append("',ORDER_CLEAR=0,ORDER_CLEARAMT=ORDER_CLEARAMT-");
        //                //    strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                //    strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                //    strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                //    strSqlToUpdateBStyleDB.Append("'|");
        //                //}
        //                //else
        //                //{
        //                strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_ACHECK=0,ORDER_ACHECKER='',ORDER_ACHECKDATE='");
        //                strSqlToUpdateBStyleDB.Append(DateTime.Now);
        //                strSqlToUpdateBStyleDB.Append("',ORDER_CLEAR=0,ORDER_CLEARAMT=ORDER_CLEARAMT-");
        //                strSqlToUpdateBStyleDB.Append(immediatePayAmount + accountPayAmount);
        //                strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
        //                strSqlToUpdateBStyleDB.Append(Request.QueryString["code"].ToString().Trim());
        //                strSqlToUpdateBStyleDB.Append("'|");
        //                //}

        //                Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
        //                if (userInfo == null)
        //                {
        //                    Share.Alert(Page, "系统内无此会员信息！"); return;
        //                }
        //                Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

        //                if (userAccount == null)
        //                {
        //                    Share.Alert(this.Page, "系统内无此会员的结余款信息，因此不能使用结余款支付！"); return;
        //                }
        //                if (accountPayAmount != 0)
        //                {
        //                    //if (accountPayAmount > userInfo.BYZD12 + userAccount.DQJE_1)
        //                    //{
        //                    //    Share.Alert(this.Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
        //                    //}

                            
        //                    string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(accountPayAmount, userInfo.DM);
        //                    strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
        //                    strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

        //                    string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("004", operatorId, operatorId, order.ORDER_CUSTOMERCODE, accountPayAmount);
        //                    strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);
                            
                            
        //                }

        //                if (strSqlToUpdateErpDB.ToString() == "")
        //                {
        //                    string stringSql = strSqlToUpdateBStyleDB.ToString();
        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
        //                    result = new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
        //                }
        //                else
        //                {
        //                    string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
        //                    string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

        //                    char[] charToTrim = new char[] { '|' };
        //                    string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
        //                    string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

        //                    ERP.Service webService = new ERP.Service();
        //                    result = webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
        //                }
        //            }
        //            #endregion                   
        //        }
        //        else
        //        {
        //            Share.Alert(Page, "支付金额不足"); return;
        //        }
        //        break;
        //    case "1":
        //        order.ORDER_ACHECK = 0;
        //        order.ORDER_ACHECKER = Share.UserValue(0);
        //        order.ORDER_ACHECKDATE = DateTime.Now;
        //        order.ORDER_LOCK = 1;
        //        result = new BLL.ORDERDOC().Update(order);
        //        break;
        //}
        //if (result)
        //{
        //    Share.InsertLog("400101", "00013");
        //    Response.Redirect("OrderDetail.aspx?code=" + Request.QueryString["code"].ToString().Trim());
        //}
        //else
        //{
        //    Share.Alert(Page, "财务反审核失败"); return;
        //}

    }
    #endregion

    #region 意见
    public void YiJian()
    {
        if (!Check.CheckPermission("400101", "00021"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        Response.Redirect("AddSuggestion.aspx?code=" + Request.QueryString["code"].ToString().Trim());
    }
    #endregion
    #region 申请退货


    public void SQTH()
    {

        if (ckbfh.Checked)
        {
            if (new BLL.RETURNDOC().IsExistNonAuditReturnDoc(Request.QueryString["code"].ToString().Trim()))
            {
                Share.Alert(Page, "该订单已被申请退货,并且退货单尚未财务审核!"); return;
            }
            Response.Redirect("NewReturnDoc.aspx?code=" + Request.QueryString["code"].ToString().Trim());
        }
        else
        {
            Share.Alert(Page, "该订单尚未发货,不允许退货！");
        }
    }
    #endregion
    #region 取消

    public void DoChanl()
    {
        Response.Redirect(Request.RawUrl);

    }
    #endregion


    #region 返回

    public void GoReturn()
    {
        Response.Redirect("OrderList.aspx");
    }
    #endregion


    #endregion

    protected void btnUpdatePayDetail_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("400101", "00002"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        if (ckbjs.Checked)
        {
            Share.Alert(this.Page, "已经结算的订单不能修改支付明细。"); return;
        }
        if (new BLL.PAYDETAIL().GetNotGetPayDetailsCountByOrderId(Request.QueryString["code"].ToString()) == 0)
        {
            Share.Alert(this.Page, "该订单的所有支付明细均以到帐，因此不能修改！"); return;
        }
        Response.Redirect("PayDetailEdit.aspx?code=" + Request.QueryString["code"].ToString());   
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("400101", "00015"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString().Trim());
        if (od.ORDER_SEND == 0)
        {
            Share.Alert(this.Page, "该订单未发货，不能结算！"); return;
        }
        Response.Redirect("OrderClear.aspx?code=" + Request.QueryString["code"].ToString());
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(Request.QueryString["code"].ToString().Trim());

        if (od.ORDER_APAY == 0)
        {
            if (Decimal.Parse(lblorderje.Text.Trim()) > Decimal.Parse(lblzfzje.Text.Trim()))
            {
                Share.Alert(Page, "支付金额不足"); return;
            }
            decimal jyk_zfje = 0.00M;
            for (int f = 0; f < DataList2.Items.Count; f++)
            {
                string selectValue = ((DropDownList)DataList2.Items[f].FindControl("ddlzflx")).SelectedValue;
                string zfje = ((TextBox)DataList2.Items[f].FindControl("txtzfje")).Text.Trim();
                string zfrq = ((DropDownList)DataList2.Items[f].FindControl("DropDownList1")).Text.Trim();
                string jyh = ((TextBox)DataList2.Items[f].FindControl("txtjyh")).Text.Trim();
                string jyrq = ((TextBox)DataList2.Items[f].FindControl("txtjyrq")).Text.Trim();
                string bz = ((TextBox)DataList2.Items[f].FindControl("txtbz")).Text.Trim();
                string zhanghao = ((TextBox)DataList2.Items[f].FindControl("txtzhanghao")).Text.Trim();

                string[] value = selectValue.Split('|');

                if (value[0] != "200")
                {
                    DataSet dst = new BLL.PAYDETAIL().GetPayDetailByPayTypeAndDealId(value[0], jyh);
                    if (dst.Tables[0].Rows.Count > 1)
                    {
                        string strInfo = "交易号为" + jyh + "的支付明细与其他订单的支付明细交易号重复，请核对交易号重新输入后保存订单，并再次审核！";
                        Share.Alert(Page, strInfo); return;
                    }
                }


                if (value[1] == "1" && jyh == "")
                {
                    Share.Alert(Page, "支付明细中交易类型为“即时到帐”或“担保交易”的，必须输入交易号和交易日期，请输入！"); return;
                }
                if (zfrq == "003")
                {
                    jyk_zfje += decimal.Parse(zfje);





                }
            }
            if (jyk_zfje > 0.00M)
            {
                Model.V_VIPSET vvs = new BLL.V_VIPSET().GetModelByGKDM(od.ORDER_CUSTOMERCODE);
                Model.V_VIP_ACCOUNT vva = new BLL.V_VIP_ACCOUNT().GetModel(vvs.DM);
                if (vva == null)
                {
                    if (0.00M + vvs.BYZD12 < jyk_zfje)
                    {
                        Share.Alert(Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
                    }
                }
                else
                {
                    if (vva.DQJE_1 + vvs.BYZD12 < jyk_zfje)
                    {
                        Share.Alert(Page, "结余款支付金额超出了结余款和信用额度之和，因此不能使用结余款支付！"); return;
                    }
                }

            }
        }
        if (new BLL.ORDERDOC().P_Order_Audit(0, System.Configuration.ConfigurationSettings.AppSettings["ckdm"].ToString(), System.Configuration.ConfigurationSettings.AppSettings["kwdm"].ToString(), Request.QueryString["code"].ToString().Trim(), Share.UserValue(0)))
        {
            Share.InsertLog("400101", "00010");
            //if (od.ORDER_APAY == 1)
            //{
            //    CAudit();
            //}
            Response.Redirect("OrderDetail.aspx?p=1&code=" + Request.QueryString["code"].ToString().Trim());
        }
        else
        {
            Share.Alert(Page, "审批失败"); return;
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        return;
    }
    protected void ckbfp_CheckedChanged(object sender, EventArgs e)
    {
        if (ckbfp.Checked)
        {
            txtfptt.Visible = true;
        }
        else
        {
            txtfptt.Visible = false;
        }
    }

    protected void ddlwlfs_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            decimal totalWeight = 0.00M;
            for (int g = 0; g < DataList1.Items.Count; g++)
            {
                string quantity = ((TextBox)DataList1.Items[g].FindControl("txtSL")).Text.Trim();
                string weight = ((Label)DataList1.Items[g].FindControl("lblWeight")).Text.Trim();

                totalWeight += Convert.ToDecimal(quantity) * Convert.ToDecimal(weight);
            }
            for (int o = 0; o < tab_sp.Rows.Count; o++)
            {
                string quantity = ((TextBox)tab_sp.Rows[o].Cells[4].Controls[0]).Text.Trim();
                string weight = ((TextBox)tab_sp.Rows[o].Cells[11].Controls[0]).Text.Trim();

                totalWeight += Convert.ToDecimal(quantity) * Convert.ToDecimal(weight);
            }

            decimal totalTranCost = new BLL.TRANERCOST().GetTranCost(ddlwlfs.SelectedValue, this.Order.ORDER_CITY, totalWeight);
            txtwlfy.Text = String.Format("{0:0.00}", totalWeight);
        }
        catch(Exception ex)
        {
            ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "click", "alert('" + ex.Message + "')", true);
        }
    }
}
